package com.skynet.amqp.perfect;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.support.CorrelationData;
import org.springframework.beans.factory.annotation.Autowired;

public class PerfectRabbitConfirmCallback implements RabbitTemplate.ConfirmCallback {

    private static final Logger log = LoggerFactory.getLogger(PerfectRabbitConfirmCallback.class);

    @Autowired
    private RetryCache retryCache;

    @Override
    public void confirm(CorrelationData correlationData, boolean ack, String cause) {
        if (ack) {
            log.info("Send message success");
            if (correlationData != null) {
                retryCache.del(Long.valueOf(correlationData.getId()));
            }
        } else {
            log.warn("Send message failed: {} -- correlationData: {}", cause, correlationData);
        }
    }

}
